package GUI;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JToolBar;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.ImageIcon;

import Client.HTSMain;
import Logic.LoginInfo;

import javax.swing.JInternalFrame;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.SwingConstants;
import java.awt.ComponentOrientation;
import java.awt.Component;
import java.awt.Cursor;

public class Menu extends JPanel {
	
	static public JButton btnRun= null;
	static public JButton StopButton = null;
	static public JButton btnHome = null;
	static public JButton btnScenarioBank= null;
	static public JButton btnAddScen = null;
	static public JButton btnDeleteScen=null;
	static public JButton btnUpdatescenario= null;
	static public JButton btnAddUser=null; 
	static public JButton btnStatistic=null;
	static public JButton btnExit = null; 
	private JTextField VesiontextField;
	private JTextField ScenarioNametextField;
	public static JInternalFrame AddScenarioFrame;
	private JComboBox ProjectcomboBox;
	
	public Menu() {
		setLayout(null);
		
		JToolBar toolBar = new JToolBar();
		toolBar.setFloatable(false);
		toolBar.setBounds(10, 0, 985, 91);
		add(toolBar);
		

		btnHome = new JButton("");
		btnHome.setVerticalTextPosition(SwingConstants.BOTTOM);
		btnHome.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnHome.setActionCommand("\r\nCenter");
		btnHome.setAlignmentX(Component.CENTER_ALIGNMENT);
		btnHome.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				ArrayList AddArray=new ArrayList();
	 			AddArray.add("Center");
	 			HTSMain.chat.handleMessageFromGui(AddArray);
				
				
			}
		});
		btnHome.setToolTipText("Center");
		btnHome.setIcon(new ImageIcon(Menu.class.getResource("/Images/29_House_48x48.png")));
		toolBar.add(btnHome);
		
		btnScenarioBank = new JButton("");
		btnScenarioBank.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnScenarioBank.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				ArrayList Arr=new ArrayList();
				Arr.add("Bank");
	 			HTSMain.chat.handleMessageFromGui(Arr);
				
				
			}
		});
		btnScenarioBank.setToolTipText("Scenario Bank");
		btnScenarioBank.setIcon(new ImageIcon(Menu.class.getResource("/Images/box_48.png")));
		toolBar.add(btnScenarioBank);
		
		 btnRun = new JButton("");
		 btnRun.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	
		  btnRun.setEnabled(false);
		btnRun.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				ArrayList<Object> AddArray=new ArrayList<Object>();
	 			
	 			String Version = JOptionPane.showInputDialog(null, "Please enter version number", "Input",JOptionPane.INFORMATION_MESSAGE);
	 			if(Version == null || Version.equals(""))
	 			{
	 				JOptionPane.showMessageDialog(null, "please enter version number");

	 			}
	 			else
	 			{
	 				AddArray.add("Run");
	 				AddArray.add(Bank.scenarioId);
	 				AddArray.add(Version);
	 				AddArray.add(LoginInfo.UserName);
	 				HTSMain.chat.handleMessageFromGui(AddArray);
	 			}
	 			
	 			
					
			}
		});
		btnRun.setIcon(new ImageIcon(Menu.class.getResource("/Images/Play-Pressed-icon.png")));
		btnRun.setToolTipText("Run");
		toolBar.add(btnRun);
		
		btnAddScen = new JButton("");
		btnAddScen.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnAddScen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				AddScenarioFrame.setVisible(true);
				
				
				
			}
		});
		
		StopButton = new JButton("");
		StopButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		StopButton.setToolTipText("Stop");
		StopButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				ArrayList AddArray=new ArrayList();
	 			AddArray.add("StopScenario");
	 			AddArray.add(Run.ScenarioRun);			
	 			HTSMain.chat.handleMessageFromGui(AddArray);
				
				
				
			}
		});
		StopButton.setIcon(new ImageIcon(Menu.class.getResource("/Images/Stop-Normal-Red-icon.png")));
		toolBar.add(StopButton);
		StopButton.setEnabled(false);
		btnAddScen.setToolTipText("Add Scenario");
		btnAddScen.setIcon(new ImageIcon(Menu.class.getResource("/Images/document_add_48.png")));
		toolBar.add(btnAddScen);
		
		btnDeleteScen = new JButton("");
		btnDeleteScen.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnDeleteScen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				
				int reply = JOptionPane.showConfirmDialog(null, "Are you Sure ?", "Delete Scenario", JOptionPane.YES_NO_OPTION);
		        if (reply == JOptionPane.YES_OPTION) {
		        	
		        	ArrayList AddArray=new ArrayList();
		 			AddArray.add("DeleteScenario");
		 			AddArray.add(Bank.scenarioName);			
		 			HTSMain.chat.handleMessageFromGui(AddArray);
		        }
		        else {
		           
		        }
				

			}
		});
		btnDeleteScen.setToolTipText("Delete Scenario");
		btnDeleteScen.setIcon(new ImageIcon(Menu.class.getResource("/Images/document_delete_48.png")));
		toolBar.add(btnDeleteScen);
		
		btnUpdatescenario = new JButton("");
		btnUpdatescenario.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnUpdatescenario.setToolTipText("Update Scenario");
		btnUpdatescenario.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
			
				
			}
		});
		btnUpdatescenario.setIcon(new ImageIcon(Menu.class.getResource("/Images/Edit-Document.png")));
		toolBar.add(btnUpdatescenario);
		
		btnAddUser = new JButton("");
		btnAddUser.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnAddUser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				AddUser au = new AddUser();			
				MainScreen.card.add("AddUser", au);
				MainScreen.cardLayot.show(MainScreen.card, "AddUser");
				
				
			}
		});
		btnAddUser.setToolTipText("Add New User");
		btnAddUser.setIcon(new ImageIcon(Menu.class.getResource("/Images/AddUser.png")));
		toolBar.add(btnAddUser);
		
		btnStatistic = new JButton("");
		btnStatistic.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnStatistic.setToolTipText("Statistic");
		btnStatistic.setIcon(new ImageIcon(Menu.class.getResource("/Images/rsz_statstic.png")));
		btnStatistic.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		toolBar.add(btnStatistic);
		
		btnExit = new JButton("");
		btnExit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnExit.setToolTipText("Exit");
		toolBar.add(btnExit);
		btnExit.setIcon(new ImageIcon(Menu.class.getResource("/Images/rsz_logout-icon.png")));
		btnExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				ArrayList<String> Arr=new ArrayList<String>();
				Arr.add("Logout");
				Arr.add("0");
				Arr.add(LoginInfo.UserName);
				HTSMain.chat.handleMessageFromGui(Arr);
				MainScreen.cardLayot.show(MainScreen.card, "Login");
				
				
			}
		});
		
		JLabel SpaceButton_1 = new JLabel("                                             ");
		toolBar.add(SpaceButton_1);
		
		JLabel btnNewButton = new JLabel("");
		btnNewButton.setAlignmentX(Component.RIGHT_ALIGNMENT);
		btnNewButton.setAlignmentY(Component.BOTTOM_ALIGNMENT);
		btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 12));
		btnNewButton.setToolTipText("Logo\r\n");
		btnNewButton.setHorizontalAlignment(SwingConstants.CENTER);
		btnNewButton.setIcon(new ImageIcon(Menu.class.getResource("/Images/HTS_logo.png")));
		toolBar.add(btnNewButton);
		
		AddScenarioFrame = new JInternalFrame("Add Scenario");
		AddScenarioFrame.setClosable(true);
		AddScenarioFrame.setBounds(210, 136, 362, 228);
		add(AddScenarioFrame);
		AddScenarioFrame.getContentPane().setLayout(null);
		
		JLabel ScenarioNameLabel = new JLabel("Scenario name:");
		ScenarioNameLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
		ScenarioNameLabel.setBounds(28, 43, 117, 35);
		AddScenarioFrame.getContentPane().add(ScenarioNameLabel);
		
		JLabel VersionLabel = new JLabel("Version:");
		VersionLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
		VersionLabel.setBounds(28, 96, 88, 17);
		AddScenarioFrame.getContentPane().add(VersionLabel);
		
		VesiontextField = new JTextField();
		VesiontextField.setFont(new Font("Tahoma", Font.PLAIN, 14));
		VesiontextField.setBounds(140, 89, 126, 35);
		AddScenarioFrame.getContentPane().add(VesiontextField);
		VesiontextField.setColumns(10);
		
		ScenarioNametextField = new JTextField();
		ScenarioNametextField.setFont(new Font("Tahoma", Font.PLAIN, 14));
		ScenarioNametextField.setBounds(140, 43, 126, 35);
		AddScenarioFrame.getContentPane().add(ScenarioNametextField);
		ScenarioNametextField.setColumns(10);
		
		JButton btnCreate = new JButton("Create"); // Button Create
		btnCreate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				ArrayList AddArray=new ArrayList();
	 			AddArray.add("AddScenario");
	 			AddArray.add(ScenarioNametextField.getText());
	 			AddArray.add(VesiontextField.getText());
	 			AddArray.add(ProjectcomboBox.getSelectedItem());
	 			HTSMain.chat.handleMessageFromGui(AddArray);
				
				
				
			}
		});
		btnCreate.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnCreate.setBounds(140, 165, 89, 23);
		AddScenarioFrame.getContentPane().add(btnCreate);
		
		JLabel lblProject = new JLabel("Project:");
		lblProject.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblProject.setBounds(28, 140, 88, 17);
		AddScenarioFrame.getContentPane().add(lblProject);
		
		ProjectcomboBox = new JComboBox();
		ProjectcomboBox.addItem("CCR");
		ProjectcomboBox.addItem("VRS");
		ProjectcomboBox.addItem("Other");
		
		ProjectcomboBox.setFont(new Font("Tahoma", Font.PLAIN, 14));
		ProjectcomboBox.setBounds(140, 135, 126, 22);
		AddScenarioFrame.getContentPane().add(ProjectcomboBox);
		AddScenarioFrame.setVisible(false);
	}
}
